package io.renren.modules.user.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.sys.controller.AbstractController;
import io.renren.modules.user.service.UserStudentService;
import io.renren.modules.user.service.UserTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

@RestController
@RequestMapping("/user/teacher")
public class UserTeacherController extends AbstractController {
    @Autowired
    private UserTeacherService userTeacherService;
    /*
    获得列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String,Object> param){
        PageUtils result = userTeacherService.queryList(param);
        return R.ok().put("page",result);
    }
    /*
    新增老师用户
     */
    @PostMapping("/save")
    public R add(@RequestBody Map<String,Object> data){
        data.put("createUser",getUserId());
        data.put("createTime",new Date());
        userTeacherService.addUser(data);
        return R.ok();
    }

    /*
    更新
     */
    @PostMapping("/update")
    public R update(@RequestBody Map<String,Object> data){
        data.put("updateUser",getUserId());
        data.put("updateTime",new Date());
        userTeacherService.updateUser(data);
        return R.ok();
    }

    /*
    获得表单数据
     */
    @RequestMapping("/data/{userId}")
    public R data(@PathVariable("userId") String userId ){
        Map<String, Object> result = userTeacherService.queryInfo(userId);
        return R.ok().put("user",result);
    }
    

}
